package cn.com.nes.site.entity.em.crm.opportunity;

import cn.com.nes.common.exception.NoSuchEnumException;
import lombok.extern.slf4j.Slf4j;

import java.util.HashMap;
import java.util.Map;

/**
 * 商机类别 枚举
 *  值域对应 t_param 表 param_type=17
 *
 * @Author: ShenWei
 * @Date: 2024/05/10/9:36
 */
@Slf4j
public enum OpportunityTypeEnum {

    // 商机类型
    _purchase("01","设备购买"),
    _repair("02","售后维修"),
    _negotiation("03","项目洽谈"),

    ;

    OpportunityTypeEnum(String type, String title) {
        this.type = type;
        this.title = title;
    }

    private String type;

    private String title;

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public static OpportunityTypeEnum getEnum(String key) {
        Map<String, OpportunityTypeEnum> map = new HashMap<>();
        for (OpportunityTypeEnum opportunityTypeEnum : values()) {
            map.put(opportunityTypeEnum.getType(), opportunityTypeEnum);
        }
        if (!map.containsKey(key)) {
            throw new NoSuchEnumException("未匹配的商机类别");
        }
        return map.get(String.valueOf(key));
    }

    public static String enumConvertKeyToValue(String key) {
        String val = "";
        try {
            val = getEnum(key).getTitle();
        } catch (NoSuchEnumException e) {
            log.warn("{}, convert key to value error, key:[{}], cause:[{}]", e.getStackTrace()[0].getFileName(), key, e.getMessage());
        }
        return val;
    }
}
